import {
	api,
	BASE_URL
} from '../js/api.js';
import {
	defineStore
} from 'pinia';

import {
	ref
} from 'vue'

const EMPTY = {
	user: {},
	info: {},
	logo: ''
}

const store = defineStore('user', () => {
	const islogin = ref(false);
	let userinfo = ref(EMPTY);


	const queryUser = (cb) => {
		let instance = this;
		api.get('/auth/info', {}, (data) => {
			if (data.success) {
				islogin.value = true;
				userinfo.value = data.data;
				userinfo.value.logo =
					BASE_URL + '/user/info/logo/' + userinfo.value.user.id
			} else {
				islogin.value = false;
				userinfo.value = EMPTY;
			}
			cb?.(data.success);
		});
	}
	return {
		islogin,
		userinfo,
		queryUser
	}
})

export default store;